<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>欢迎页面-X-admin2.2</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<link rel="stylesheet" href="./css/font.css">
<link rel="stylesheet" href="./css/xadmin.css">
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
<style type="text/css">
	.awsui-checkbox1{
		border: solid 1px red; 
	}
	
</style>
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/xadmin.js"></script>
<!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a href="">首页</a> <a href="">演示</a>
			<a> <cite>导航元素</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			onclick="location.reload()" title="刷新"> <i
			class="layui-icon layui-icon-refresh" style="line-height: 30px"></i></a>
	</div>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body ">
					<div class="layui-inline layui-show-xs-block">
								<input type="text" name="name" id="searchNameId"
								placeholder="请输入用户名"
									autocomplete="off" class="layui-input">
							</div>
							<div class="layui-inline layui-show-xs-block">
								<button class="layui-btn" onclick="doGetObjects()" lay-submit="" lay-filter="sreach">
									<i class="layui-icon">&#xe615;</i>
								</button>
							</div>
						
					</div>
					<div class="layui-card-header">
						<button class="layui-btn layui-btn-danger" onclick="delAll()">
							<i class="layui-icon"></i>删除
						</button>
					 
						<button class="layui-btn"
						onclick="xadmin.open('添加用户','x/role-add',600,400)">
							
							<i class="layui-icon"></i>添加
						</button>
					
					</div>
					<div class="box-body table-responsive no-padding">
						<table class="layui-table">
							<thead>
								<tr>
								<!-- 
								  <input class='awsui-checkbox'  id='checkboxStyle' value='' type='checkbox'/>
									<input type="checkbox" name=""  lay-skin="primary">
									<input type="checkbox" name=""  lay-skin="primary">
									 class="icheckbox" style="display: inline-block;border: rgba(0,0,0,0.5) 1px solid;width: 10px;height: 10px;font-family: 微软雅黑;font-size: 8px;line-height: 10px;text-align: center;border-radius: 2px;" onclick="fun()" &nbsp
									 -->
                                   <!--   <th><input type="checkbox" id="checkAll">全选</th> -->
                                   
                                     <th>ID</th>
									<th>角色名</th>
									<th>拥有权限规则</th>
									<th>描述</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="tbodyId" type="cgb" ccc="100">

								<tr>
									<td>
                                    <!-- <input type="checkbox" name=""  lay-skin="primary"> -->
                                  </td>
                                  <td colspan="6">数据正在加载中......
                                  </td>
								</tr>

							</tbody>
						</table>
					</div>
					<div class="layui-card-body ">
                         <div id="pageId" class="page" th:include="page.html :: pageFragement">
                       </div>
                    </div>
				</div>
			</div>
		</div>
	</div>
  </body>
        	 
<script type="text/javascript">


//页面数据呈现模块及操作模块

    $(function(){
    	
     //初始化当前页码值
    // $("pageId").data("pagecurrent",1);
     //执行查询
    doGetObjects();
    //debugger
  //注册事件
     $(".layui-show-xs-block")
	  .on("click",".layui-btn",doQueryObjects)
   
    })
 
    function doQueryObjects(){
	$("#pageId").data("pageCurrent",1);
	
	doGetObjects();
}
    //通过此函数异步加载服务端的日志信息
    function doGetObjects(){
     //初始化全选checkbox对象状态
     $("#checkAll").prop("checked",false);
     //定义请求参数
     var pageCurrent=$("#pageId").data("pageCurrent");
     if(!pageCurrent)pageCurrent=1;
     
     //参数封装:
      let params={"pageCurrent":pageCurrent};
      
      //debugger
      var name=$("#searchNameId").val();
      
      if(name)params.name=name;
     //定义请求url
     const url="role/doFindPageObjects";
     //发送异步请求并处理响应结果
     console.log(params);
     $.getJSON(url,params,function(result){
      doHandleQueryResult(result);
     });
    }
    function doHandleQueryResult(result){
     //console.log("result",result);
     if(result.state==1){
    	
      //第一步:将当前页的日志记录信息更新到页面上
      doSetTableBodyRows(result.data.records);
     //第二步:将分页信息更新到页面上
     doSetPagination(result.data);
     }else{
      doSetQueryErrors(result.message);
     }
    }
   function doSetQueryErrors(message){
     $("#bodyId").html(`<tr><td colspan='5'>${message}</td><tr>`);
    }
    function doSetTableBodyRows(records){
     //获取tbody对象并清空内容
     var tBody=$("#tbodyId");
     tBody.empty();
    
     //遍历records,并将结果更新到页面上
     records.forEach(record=>tBody.append(doCreateRow(record)))
    }
   function doCreateRow(record){
	 
	     return `<tr>
	     <!-- <td><input type="checkbox" name=""  lay-skin="primary"></td> -->
	    
	     	<td>${record.id}</td>
	        <td>${record.name}</td>
	        <td>${record.jurisdiction}</td>
	        <td>${record.descriptive}</td>
	        <td class="td-status">
            <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
	        <td class="td-manage">
	        <a onclick="member_stop(this,'10001')" href="javascript:;"  title="启用">
            	<i class="layui-icon">&#xe601;</i>
          	</a>
	          <a title="编辑"  onclick="xadmin.open('编辑','role-add.html')" href="javascript:;">
	            <i class="layui-icon">&#xe642;</i>
	          </a>
          
		        <a title="删除" onclick="member_del(id)"  id=${record.id} href="javascript:;">
	            	<i class="layui-icon">&#xe640;</i>
	          	</a>
        </td>
	     </tr>`;
   }
   /*
       //用户-停用
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }
              
          });
      }
      */
/*用户-删除*/
function member_del(id){
    	  
 
  	  //按钮1的事件,定义处理删除操作的事件处理函数
  	 
  		
 		//1.1获取选中的id值
 		//var idArray=doGetCheckedIds();//通过此函数返回一个数组，数组中存储的选中的ids
 		//1.1.1判断有无选中
 		if(!confirm("确认删除吗？"))return;
  	 //2定义删除操作的url
  	 const url="role/doDeleteObjects";
  	//3创建参数对象
  		var params={"ids":id};//[1,2,3]-->1,2,3
  	 //4 发异步请求执行删除操作
 	    $.post(url,params,doHandleDeleteResult)

 	  	 
    }
    //处理删除结果
   function doHandleDeleteResult(result){
    	
  	  if(result.state==1){
  		
       		//并刷新页面
       		doGetObjects();
       		
       		}else{
       			alert("网络异常,请稍后再试!");
       		
       		  }
    }


   
        	 
	</script>
</html>